package com.meida.module.bus.provider.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import com.meida.module.bus.client.entity.BusVipUser;
import com.meida.module.bus.provider.mapper.BusVipUserMapper;
import com.meida.module.bus.provider.service.BusVipUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * @Description:用户扩展字段
 * @ClassName AppUserExtraUpdateServiceImpl
 * @date: 2022.06.23 14:41
 * @Author: ldd
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BusVipUserServiceImpl extends BaseServiceImpl<BusVipUserMapper, BusVipUser> implements BusVipUserService {


    @Override
    public boolean save(BusVipUser entity) {
        return this.baseMapper.insert(entity) > 0;
    }

    @Override
    public boolean updateById(BusVipUser entity) {
        return this.baseMapper.updateById(entity) > 0;
    }

    @Override
    public String getMaxGroupNumByVipTypeId(Long vipTypeId) {
        List<BusVipUser> vipUsers = baseMapper.selectList(new QueryWrapper<BusVipUser>().eq("vipTypeId", vipTypeId).orderByDesc("updateTime"));
        return CollUtil.isNotEmpty(vipUsers) ? vipUsers.get(0).getGroupNum() : "";
    }

    @Override
    public boolean saveBatch(Collection<BusVipUser> entityList) {
        return false;
    }

    @Override
    public List<BusVipUser> getBusVipUserListByVipTypeId(Long vipTypeId, String group) {
        return baseMapper.selectList(new QueryWrapper<BusVipUser>().eq("vipTypeId", vipTypeId).likeRight(StrUtil.isNotEmpty(group), "groupNum", group));
    }

    @Override
    public BusVipUser getByUserId(Long userId) {
        return getOne(new QueryWrapper<BusVipUser>().eq(true, "userId", userId));
    }

    @Override
    public List<BusVipUser> getBusVipUserListByVipGroupId(String group) {
        return baseMapper.selectList(new QueryWrapper<BusVipUser>().likeRight(StrUtil.isNotEmpty(group), "groupNum", group));
    }
}
